home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / net / MulticastSocket.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  4.6 KB  |  271 lines

  1. package java.net;
  2.  
  3. import java.io.IOException;
  4. import java.util.Enumeration;
  5.  
  6. public class MulticastSocket extends DatagramSocket {
  7.    private Object ttlLock;
  8.    private Object infLock;
  9.    private InetAddress infAddress;
  10.  
  11.    public MulticastSocket() throws IOException {
  12.       this(new InetSocketAddress(0));
  13.    }
  14.  
  15.    public MulticastSocket(int var1) throws IOException {
  16.       this(new InetSocketAddress(var1));
  17.    }
  18.  
  19.    public MulticastSocket(SocketAddress var1) throws IOException {
  20.       super((SocketAddress)null);
  21.       this.ttlLock = new Object();
  22.       this.infLock = new Object();
  23.       this.infAddress = null;
  24.       this.setReuseAddress(true);
  25.       if (var1 != null) {
  26.          this.bind(var1);
  27.       }
  28.  
  29.    }
  30.  
  31.    /** @deprecated */
  32.    @Deprecated
  33.    public void setTTL(byte var1) throws IOException {
  34.       if (this.isClosed()) {
  35.          throw new SocketException("Socket is closed");
  36.       } else {
  37.          this.getImpl().setTTL(var1);
  38.       }
  39.    }
  40.  
  41.    public void setTimeToLive(int var1) throws IOException {
  42.       if (var1 >= 0 && var1 <= 255) {
  43.          if (this.isClosed()) {
  44.             throw new SocketException("Socket is closed");
  45.          } else {
  46.             this.getImpl().setTimeToLive(var1);
  47.          }
  48.       } else {
  49.          throw new IllegalArgumentException("ttl out of range");
  50.       }
  51.    }
  52.  
  53.    /** @deprecated */
  54.    @Deprecated
  55.    public byte getTTL() throws IOException {
  56.       if (this.isClosed()) {
  57.          throw new SocketException("Socket is closed");
  58.       } else {
  59.          return this.getImpl().getTTL();
  60.       }
  61.    }
  62.  
  63.    public int getTimeToLive() throws IOException {
  64.       if (this.isClosed()) {
  65.          throw new SocketException("Socket is closed");
  66.       } else {
  67.          return this.getImpl().getTimeToLive();
  68.       }
  69.    }
  70.  
  71.    public void joinGroup(InetAddress var1) throws IOException {
  72.       if (this.isClosed()) {
  73.          throw new SocketException("Socket is closed");
  74.       } else {
  75.          SecurityManager var2 = System.getSecurityManager();
  76.          if (var2 != null) {
  77.             var2.checkMulticast(var1);
  78.          }
  79.  
  80.          if (!var1.isMulticastAddress()) {
  81.             throw new SocketException("Not a multicast address");
  82.          } else {
  83.             this.getImpl().join(var1);
  84.          }
  85.       }
  86.    }
  87.  
  88.    public void leaveGroup(InetAddress var1) throws IOException {
  89.       if (this.isClosed()) {
  90.          throw new SocketException("Socket is closed");
  91.       } else {
  92.          SecurityManager var2 = System.getSecurityManager();
  93.          if (var2 != null) {
  94.             var2.checkMulticast(var1);
  95.          }
  96.  
  97.          if (!var1.isMulticastAddress()) {
  98.             throw new SocketException("Not a multicast address");
  99.          } else {
  100.             this.getImpl().leave(var1);
  101.          }
  102.       }
  103.    }
  104.  
  105.    public void joinGroup(SocketAddress var1, NetworkInterface var2) throws IOException {
  106.       if (this.isClosed()) {
  107.          throw new SocketException("Socket is closed");
  108.       } else if (var1 != null && var1 instanceof InetSocketAddress) {
  109.          if (this.oldImpl) {
  110.             throw new UnsupportedOperationException();
  111.          } else {
  112.             SecurityManager var3 = System.getSecurityManager();
  113.             if (var3 != null) {
  114.                var3.checkMulticast(((InetSocketAddress)var1).getAddress());
  115.             }
  116.  
  117.             if (!((InetSocketAddress)var1).getAddress().isMulticastAddress()) {
  118.                throw new SocketException("Not a multicast address");
  119.             } else {
  120.                this.getImpl().joinGroup(var1, var2);
  121.             }
  122.          }
  123.       } else {
  124.          throw new IllegalArgumentException("Unsupported address type");
  125.       }
  126.    }
  127.  
  128.    public void leaveGroup(SocketAddress var1, NetworkInterface var2) throws IOException {
  129.       if (this.isClosed()) {
  130.          throw new SocketException("Socket is closed");
  131.       } else if (var1 != null && var1 instanceof InetSocketAddress) {
  132.          if (this.oldImpl) {
  133.             throw new UnsupportedOperationException();
  134.          } else {
  135.             SecurityManager var3 = System.getSecurityManager();
  136.             if (var3 != null) {
  137.                var3.checkMulticast(((InetSocketAddress)var1).getAddress());
  138.             }
  139.  
  140.             if (!((InetSocketAddress)var1).getAddress().isMulticastAddress()) {
  141.                throw new SocketException("Not a multicast address");
  142.             } else {
  143.                this.getImpl().leaveGroup(var1, var2);
  144.             }
  145.          }
  146.       } else {
  147.          throw new IllegalArgumentException("Unsupported address type");
  148.       }
  149.    }
  150.  
  151.    public void setInterface(InetAddress var1) throws SocketException {
  152.       if (this.isClosed()) {
  153.          throw new SocketException("Socket is closed");
  154.       } else {
  155.          synchronized(this.infLock) {
  156.             this.getImpl().setOption(16, var1);
  157.             this.infAddress = var1;
  158.          }
  159.       }
  160.    }
  161.  
  162.    public InetAddress getInterface() throws SocketException {
  163.       if (this.isClosed()) {
  164.          throw new SocketException("Socket is closed");
  165.       } else {
  166.          synchronized(this.infLock) {
  167.             InetAddress var2 = (InetAddress)this.getImpl().getOption(16);
  168.             if (this.infAddress == null) {
  169.                return var2;
  170.             } else if (var2.equals(this.infAddress)) {
  171.                return var2;
  172.             } else {
  173.                InetAddress var9;
  174.                try {
  175.                   NetworkInterface var3 = NetworkInterface.getByInetAddress(var2);
  176.                   Enumeration var4 = var3.getInetAddresses();
  177.  
  178.                   while(var4.hasMoreElements()) {
  179.                      InetAddress var5 = (InetAddress)var4.nextElement();
  180.                      if (var5.equals(this.infAddress)) {
  181.                         var9 = this.infAddress;
  182.                         return var9;
  183.                      }
  184.                   }
  185.  
  186.                   this.infAddress = null;
  187.                   var9 = var2;
  188.                } catch (Exception var7) {
  189.                   return var2;
  190.                }
  191.  
  192.                return var9;
  193.             }
  194.          }
  195.       }
  196.    }
  197.  
  198.    public void setNetworkInterface(NetworkInterface var1) throws SocketException {
  199.       synchronized(this.infLock) {
  200.          this.getImpl().setOption(31, var1);
  201.          this.infAddress = null;
  202.       }
  203.    }
  204.  
  205.    public NetworkInterface getNetworkInterface() throws SocketException {
  206.       NetworkInterface var1 = (NetworkInterface)this.getImpl().getOption(31);
  207.       if (var1.getIndex() == 0) {
  208.          InetAddress[] var2 = new InetAddress[]{InetAddress.anyLocalAddress()};
  209.          return new NetworkInterface(var2[0].getHostName(), 0, var2);
  210.       } else {
  211.          return var1;
  212.       }
  213.    }
  214.  
  215.    public void setLoopbackMode(boolean var1) throws SocketException {
  216.       this.getImpl().setOption(18, var1);
  217.    }
  218.  
  219.    public boolean getLoopbackMode() throws SocketException {
  220.       return (Boolean)this.getImpl().getOption(18);
  221.    }
  222.  
  223.    /** @deprecated */
  224.    @Deprecated
  225.    public void send(DatagramPacket var1, byte var2) throws IOException {
  226.       if (this.isClosed()) {
  227.          throw new SocketException("Socket is closed");
  228.       } else {
  229.          synchronized(this.ttlLock) {
  230.             synchronized(var1) {
  231.                if (this.connectState == 0) {
  232.                   SecurityManager var16 = System.getSecurityManager();
  233.                   if (var16 != null) {
  234.                      if (var1.getAddress().isMulticastAddress()) {
  235.                         var16.checkMulticast(var1.getAddress(), var2);
  236.                      } else {
  237.                         var16.checkConnect(var1.getAddress().getHostAddress(), var1.getPort());
  238.                      }
  239.                   }
  240.                } else {
  241.                   Object var5 = null;
  242.                   InetAddress var15 = var1.getAddress();
  243.                   if (var15 == null) {
  244.                      var1.setAddress(this.connectedAddress);
  245.                      var1.setPort(this.connectedPort);
  246.                   } else if (!var15.equals(this.connectedAddress) || var1.getPort() != this.connectedPort) {
  247.                      throw new SecurityException("connected address and packet address differ");
  248.                   }
  249.                }
  250.  
  251.                byte var17 = this.getTTL();
  252.  
  253.                try {
  254.                   if (var2 != var17) {
  255.                      this.getImpl().setTTL(var2);
  256.                   }
  257.  
  258.                   this.getImpl().send(var1);
  259.                } finally {
  260.                   if (var2 != var17) {
  261.                      this.getImpl().setTTL(var17);
  262.                   }
  263.  
  264.                }
  265.             }
  266.  
  267.          }
  268.       }
  269.    }
  270. }
  271.